import { getWork } from "@fujocoded/ao3.js" import { setArchiveBaseUrl, getArchiveBaseUrl, resetArchiveBaseUrl } from "@fujocoded/ao3.js/urls" export async function GET(req, ctx) { const { workId } = await ctx.params const params = await req.nextUrl.searchParams const domain = await req.nextUrl.hostname const subdomain = (domain.split(".").length > 2) ? domain.split(".")[0] : null const archive = params ? params.get('archive') : null if (subdomain) setArchiveBaseUrl('https://'+siteMap[subdomain]) if (archive) setArchiveBaseUrl(archive) const work = await getWork({workId: workId}) if (archive || subdomain) resetArchiveBaseUrl() return Response.json(work) }